package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;



public class ConnectionFactory {
	
	private static final String BANCO = "jdbc:postgresql://localhost:5432/siscomp";
	private static final String USER = "postgres";
	private static final String PASS = "s120159x";
	private static final String DRIVER = "org.postgresql.Driver";
	private static Connection instance = null;
	
	
	
	public static Connection getConnection() throws Exception{
		
		
		try{
			
			
			Class.forName(DRIVER);
			
			instance =  (Connection) DriverManager.getConnection(BANCO,USER,PASS); 
			return instance;
 			
			
		}catch(SQLException ex){
			
			throw new RuntimeException(ex);
		}

	}
	
	
	public static Connection getInstance() throws Exception{
		
		if(instance == null || instance.isClosed()) 
			return getConnection();
		else
			return instance;
	
		
	}

}
